import javax.swing.tree.TreeNode;

class Solution {
    public static class TreeNode{
        public int val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
    }

    //平衡树实现
    public boolean isBalanced(TreeNode root) {
        if(root==null){
            return true;
        }
        int lh=getHight(root.left);
        int rh=getHight(root.right);
        return Math.abs(lh-rh)<=1 && isBalanced(root.left) && isBalanced(root.right);
    }
    public int getHight(TreeNode root){
        if(root==null){
            return 0;
        }
        int lh=getHight(root.left);
        int rh=getHight(root.right);
        return Math.max(lh,rh)+1;
    }
}
